package com.weibo.servlet;

import java.io.IOException;
import java.io.PrintWriter;
import java.sql.ResultSet;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;

import com.weibo.hibernate.PersonInfo;

public class rInfo extends HttpServlet{
	public rInfo(){super();};
	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		request.setCharacterEncoding("UTF-8");
		response.setContentType("text/html; charset=UTF-8");
		PrintWriter out=response.getWriter();
		String regName=request.getParameter("regName");
		SessionFactory sessionFactory=HibernateUtil.getSessionFactory();
		//打开一个session实例
		Session session=sessionFactory.openSession();
		
		Transaction query= session.beginTransaction();//开始事务
//		String hql="from personInfo where regName='regName'";//查询hql语句		
//		Query userInfo=session.createQuery(hql);//执行查询，查询结果为Query实例	
		PersonInfo p2=(PersonInfo)session.get(PersonInfo.class, "5");
		System.out.println("注册名："+p2.getRegName());
		System.out.println("用户名："+p2.getUserName());
		System.out.println("性别: "+ p2.isGender());
		System.out.println("Email: "+ p2.getEmail());
//		System.out.println("真实姓名："+ p2.getRealName());
		System.out.println("国家："+p2.getStatement());	
		System.out.println("Province: "+p2.getProvince());
		System.out.println("City: "+p2.getCity());		
		System.out.println("出生日期："+p2.getBirYear()+ p2.getBirMonth()+ p2.getBirDay());		
		System.out.println("QQ: "+p2.getQQ());		
		System.out.println("MSN: "+p2.getMSN());
	

//		List list=userInfo.list();//将查询结果放到一个list中		
		query.commit();//提交事务
		//关闭session
		session.close();		
		out.flush();
		out.close();
	}

	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

	}
}
